<?php
/**
 * 模块-评论前台管理 
 * CommentController.php
 * ==============================================
 * 版权所有 2013-2014
 * ----------------------------------------------
 * 这不是一个自由软件，未经授权不许任何使用和传播。
 * -------------------------------
 * 
 * @package xcs
 * @author huangdaohai <huangdaohai.2007@163.com>
 * @version V1.0
 * @access public
 */
class CommentController extends Controller
{	//首页
    public $layout = '/layouts/empty';
	public function actionIndex(){ 
	   //获取相关参数
       $aParams['comment_type'] = $this->_request->getQuery('comment_type' ,'content');
       $aParams['cat_id'] = $this->_request->getQuery('cat_id');
       $aParams['content_id'] = $this->_request->getQuery('content_id');
       $aParams['page'] = $this->_request->getQuery('page');
       $aParams['pagesize'] = $this->_request->getQuery('pagesize' ,2);
	   //获取配置
       $oModule = new BaseModule();
       $aComment = $oModule->getOne('comment');
       $aSetting = unserialize($aComment['setting']);
       $aParams['status'] = (isset($aSetting['ischeck']) && $aSetting['ischeck']==1) ? 2 : 1;
       //获取当前页面的评论内容
       $oCommentModel = new ModuleCommentModel();
       $aCommentList = $oCommentModel->getList($aParams);
       $this->renderPartial('index' ,array('aSetting'=>$aSetting ,'aParams'=>$aParams ,'aCommentList'=>$aCommentList));
	}
    public function actionAdd(){
        $oModel = new ModuleCommentModel();
        if( $_POST ){
            //检查验证码
            if(isset($_POST['verifyCode']) && ! empty( $_POST['verifyCode'] ) ){
                //echo $this->checkCaptcha(trim($_POST['verifyCode'])) .'1234';exit;
                if( ! $this->checkCaptcha(trim($_POST['verifyCode'])) ) $this->showMessage(1 ,'验证码错误' ,$this->createUrl('comment/index'));
            }
            $oModel->attributes = $_POST;
            $oModel->createtime = time();
            $oModel->updatetime = time();
            $oModel->uid = (int)Yii::app()->user->id;
            $oModel->ip = Yii::app()->common->getIp();
            if($oModel->save()){
                $this->showMessage(0 ,'保存成功' ,$this->createUrl('comment/index'));
            } else{
                print_r($oModel->errors);
            }
            
       }
    }    
}